﻿using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using PefStudio.Base;

namespace PefStudio.Windows
{
    class CreateService
    {
        internal static void CreateMenu(ItemCollection itemCollection, IEnumerable<IMenuItem> items, Window parentWindow)
        {
            var sortedExtensionItems = ExtensionsService.Sort(items);
            foreach (var extensionItem in sortedExtensionItems)
            {
                if (extensionItem.HasSeparator == true && itemCollection.Count > 0)
                {
                    var separator = new Separator();
                    itemCollection.Add(separator);
                    extensionItem.Separator = separator;
                }
                extensionItem.ParentWindow = parentWindow;

                var toolStripItem = extensionItem as AbstractMenuItem;
                if (toolStripItem != null) itemCollection.Add(toolStripItem);
            }
        }

        internal static void CreateStatusBar(ItemCollection itemCollection, IEnumerable<IStatusBarItem> items)
        {
            var sortedExtensionItems = ExtensionsService.Sort(items);
            foreach (var extensionItem in sortedExtensionItems)
            {
                if (extensionItem.HasSeparator == true && itemCollection.Count > 1)
                    itemCollection.Add(new Separator());

                var toolStripItem = extensionItem as AbstractStatusBarItem;
                if (toolStripItem != null) itemCollection.Add(toolStripItem);
            }
        }

        internal static void CreateToolbar(ItemCollection itemCollection, IEnumerable<IToolBarItem> items)
        {
            var sortedExtensionItems = ExtensionsService.Sort(items);
            foreach (var extensionItem in sortedExtensionItems)
            {
                if (extensionItem.HasSeparator == true && itemCollection.Count > 1)
                    itemCollection.Add(new Separator());

                itemCollection.Add(extensionItem);
                //var toolStripItem = extensionItem as AbstractToolBarItem;
                //if (toolStripItem != null) itemCollection.Add(toolStripItem);
            }
        }
    }
}
